<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>main—index-TL</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../../../css/mui.poppicker.css" rel="stylesheet" />
		<link href="../../../../css/task.css" rel="stylesheet" />
		<style type="text/css">
			.addbg{
				width: 100%;
				overflow: auto;
				text-align: center;
				margin: 10px auto 5px;
			}
			.addbg .mui-btn{
				background: #ea1e1a;
				color: #fff;
				border: 0;
				border-radius: 5px;
			}
			.item_box .item .text span.cen{
				margin-left:0;
				width: auto;
			}
			.selectDate{
				float: left;
				color: #a9a9a9;
			}
			#div1 {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}
					
			#div2 {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}
					
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		
		<div id="div1"></div>
		<div id="popover1" class="mui-popover shadow popover">
		 <p class="title" id="title">您确定要删除该报告吗？</p >
		 <div class="btn_box">
		  <span class="fl" onclick="closePopover1()">取消</span>
		  <span class="fr red" onclick="fixedDel1()">确定</span>
		 </div>
		</div>
		
		<div id="div2"></div>
		<div id="popover2" class="mui-popover shadow popover">
		 <p class="title" id="title">您确定要删除该报告吗？</p >
		 <div class="btn_box">
		  <span class="fl" onclick="closePopover2()">取消</span>
		  <span class="fr red" onclick="fixedDel2()">确定</span>
		 </div>
		</div>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="mui-title" class="mui-title"></h1>
		</header>
		<div class="mui-content">
			
			<ul class="page_cen shadow xiujiaTab">
				<!--选中状态  class="cur"-->
				<li class="btn" id="err" style="display: none;"><span class="i_3">Error Report</span></li>
				<li class="btn" id="hot"><span class="i_4">Hot Account Report</span></li>
			</ul>
			<div class="page_cen shadow title_num" id="dianji">服务通知编号：<span id="serviceNo" style="color: #ea1e1a;"></span></div>
			<div class="page_cen shadow zp_cen" style="z-index: 1; position: relative;">
				<div class="zp_sear bor_1 autoHeight">
					<button class="btn" id="search"></button>
					<div class="iptBox">
						<input type="text" id="fseName" placeholder="请输入工程师姓名" />
					</div>
				</div>
				<div class="serarch_btm">
					<button id="end" type="button" class="selectDate wid">请选择日期</button>
				</div>
				<div class="addbg">
					<button id="tjbg" class="mui-btn input" type='button'>添加报告</button>
				</div>
			</div>
			<div class="item_box" id="itemBox">
			</div>
		</div>
		
		
		
		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<script src="../../../../js/mui.picker.js"></script>
		<script src="../../../../js/mui.poppicker.js"></script>
		<script src="../../../../js/utils/rolldate.min.js"></script>
		<!-- 基础js end -->

		<script>
			var serviceNo;
			var serviceType;
			var state;
			var planId;
			var noticeId;
			var problem;
			var divBu;
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					
					new Rolldate({
						el: '#end',
						format: 'YYYY-MM-DD',
						beginYear: 2015,
						endYear: 2050,
						trigger: 'click',
						lang: {
							title: '请选择日期',
						},
						confirm: function(date) {
							
						}
					})
					
					var self = plus.webview.currentWebview();
					serviceNo = self.serviceNo;
					serviceType = self.serviceType;
					planId = self.planId;
					noticeId = self.noticeId;
					problem = self.problem;
					divBu = self.divBu;
					console.log("noticeId:"+noticeId)
					console.log("planId:"+planId)
					console.log("serviceNo:"+serviceNo)
					console.log("problem:"+problem)
					h('#serviceNo').html(serviceNo);
					
					if (self.isShowAddBtn == false) {
						h('#tjbg').parent().hide()
					}
					if (serviceType == '安装') {
						state = 0;
						h('#mui-title').html('Error Report & Hot Account Report列表')		
						h("#err").show()
						h("#err").addClass('cur')
						h("#hot").removeClass('cur')
						h('#end').html('请选择日期')
						h('#fseName').val('')
						errList()
					} else {
						state = 1;
						h('#mui-title').html('Hot Account Report列表')
						h("#err").hide()
						h("#err").removeClass('cur')
						h("#hot").addClass('cur')
						h("#hot").css({'width':'100%'})
						h('#end').html('请选择日期')
						h('#fseName').val('')
						state = 1;
						hotList()
					}
										
					//点击error
					h('#err').tap(function() {
						h("#hot").removeClass('cur')
						h("#err").addClass('cur')
						h('#end').html('请选择日期')
						h('#fseName').val('')
						state = 0;
						errList()		
					})
					
					//点击hot
					h('#hot').tap(function() {
						h("#err").removeClass('cur')
						h("#hot").addClass('cur')
						h('#end').html('请选择日期')
						h('#fseName').val('')
						state = 1;
						hotList()
					})
					
					h('#tjbg').tap(function() {
						console.log(state)
						if(state === 0){
							app.jumpTo('/view/service/report/errorhot/errorReportAdd.html','view/service/report/errorhot/errorReportAdd.html',{serviceNo:serviceNo,planId:planId,noticeId:noticeId})
							
							// 以下是旧的代码逻辑 （2020/5/8 bug 除安装（安装&安装准备）外的服务通知中，不可添加Error Report）
							/* ajaxGet(BASE_URL + "cc/notice/getDaiZhiPaiNoticeDetail", {
								"ServiceNoticeId": noticeId
							}, function(data) {
								console.log(JSON.stringify(data))
								if (data.code == 200) {
									if (data.data != "") {
										var serviceType = data.data.serviceType;
										if(serviceType!='安装'){
											app.toast("非安装单，不能添加ErrorRepor")
											return
										}else{
											app.jumpTo('/view/service/report/errorhot/errorReportAdd.html','view/service/report/errorhot/errorReportAdd.html',{serviceNo:serviceNo,planId:planId,noticeId:noticeId})
										}
									}
								}
							}, function(errorMsg) {
								console.log(JSON.stringify(errorMsg))
							});	 */
						}else{
							app.jumpTo('/view/service/report/errorhot/hotReportAdd.html','view/service/report/errorhot/hotReportAdd.html',{serviceNo:serviceNo,planId:planId,noticeId:noticeId,problem:problem,divBu:divBu})
						}
					})
					
					h('#search').tap(function(){
						if(state === 0){
							errList()
						} else {
							hotList()
						}
					})
					
					h("#dianji").tap(function(){
					    app.jumpTo("/view/workArea/service/serveDetails.html", "view/workArea/service/serveDetails.html", {
					        "serviceNo": serviceNo,
					        "enginnerId": app.getUser().enginnerId
					    })
					})
				})
			})(mui, document);
			
			function errList(){
				h('#itemBox').html("");
				var fseName = h('#fseName').val() || '';
				var end = h('#end').html()
				if (!end || end == '请选择日期') {
					end = ''
				}
				app.hideSoftKeybord()
				app.showWaiting()
				ajaxGet(BASE_URL + "cc/error/report/selectErrorReport", {
					"serviceNo": serviceNo,
					fseName,
					createTime: end
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						console.log(JSON.stringify(data))
						var str = '';
						if (data.data && data.data.length > 0) {
							for(var c = 0;c<data.data.length;c++){
								console.log(JSON.stringify(data))
								str += '<div class="item">';
								str += '<div class="bar">';
								str += '<span class="del" onclick="delErrorReport('+data.data[c].id+')">删除</span>';
								str += '<span class="number" onclick="jumpToErrorReportEdit('+data.data[c].serviceNo+','+data.data[c].planId+','+data.data[c].noticeId+','+data.data[c].batchType+','+data.data[c].syncFlag+','+data.data[c].reportNo+')">'+data.data[c].id+'<img src="../../../../images/icon_204.png" /></span>';
								str += '</div>';
								str += '<div class="type" onclick="jumpToErrorReportEdit('+data.data[c].serviceNo+','+data.data[c].planId+','+data.data[c].noticeId+','+data.data[c].batchType+','+data.data[c].syncFlag+','+data.data[c].reportNo+')">';
								str += '<p><img src="../../../../images/icon_202.png"/>创建时间：<span>'+data.data[c].createTime+'</span></p>'
								var submitStatus = "";
								if (data.data[c].syncFlag == '1') {
									submitStatus = "已提交"
								} else {
									submitStatus = "未提交"
								}
								str += '<p><img src="../../../../images/icon_224.png"/>是否提交：<span>'+submitStatus+'</span></p>';
								str += '<p><img src="../../../../images/icon_104_cur.png"/>CC报告编号：<span>'+data.data[c].reportNo+'</span></p>';
								str += '</div>';
								str += '</div>';
							}
							h('#itemBox').html(str);
						} else {
							noData()
						}
					} else {
						noData()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					noData()
					app.toast(errorMsg)
				});
			}
			
			function hotList(){
				h('#itemBox').html("");
				var fseName = h('#fseName').val() || '';
				var end = h('#end').html()
				if (!end || end == '请选择日期') {
					end = ''
				}
				app.hideSoftKeybord()
				app.showWaiting()
				ajaxGet(BASE_URL + "cc/hot/account/report/selectHotReport", {
					"serviceNo": serviceNo,
					fseName,
					createTime: end
				}, function(data) {
					app.closeWaiting()
					console.log(JSON.stringify(data))
					if (data.code === 200) {
						if (data.data && data.data.length > 0) {
							var str = '';
							for(var c = 0;c<data.data.length;c++){
								var submitStr = '';
								if (data.data[c].syncFlag == '1') {
									submitStr = '已提交';
								} else {
									submitStr = '未提交';
								}
								
								str += '<div class="item">';
								str += '<div class="bar">';
								str += '<span class="del" onclick="delHotAccountReport('+data.data[c].id+')">删除</span>';
								str += '<span class="number" onclick="jumpToHotAccountEdit('+data.data[c].serviceNo+','+data.data[c].planId+','+data.data[c].noticeId+','+data.data[c].batchType+','+data.data[c].syncFlag+','+data.data[c].reportNo+')">'+data.data[c].id+'<img src="../../../../images/icon_204.png" /></span>';
								str += '</div>';
								str += '<div class="type" onclick="jumpToHotAccountEdit('+data.data[c].serviceNo+','+data.data[c].planId+','+data.data[c].noticeId+','+data.data[c].batchType+','+data.data[c].syncFlag+','+data.data[c].reportNo+')">';
								str += '<p><img src="../../../../images/icon_202.png"/>创建时间：<span>'+data.data[c].createTime+'</span></p>';
								str += '<p><img src="../../../../images/icon_224.png"/>是否提交：<span>'+submitStr+'</span></p>';
								str += '<p><img src="../../../../images/icon_104_cur.png"/>CC报告编号：<span>'+data.data[c].reportNo+'</span></p>';
								str += '</div>';
								str += '</div>';
							}
							h('#itemBox').html(str);
						} else {
							noData()
						}
					} else {
						noData()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					noData()
					app.toast(errorMsg)
				});
			}
			
			function jumpToErrorReportEdit(serviceNo, planId, noticeId, errId, submitStatus,reportGuid) {
				if(submitStatus === 1){
					// app.jumpTo('/view/service/report/errorhot/errorReportEdit.html', 'view/service/report/errorhot/errorReportEdit.html', {
					app.jumpTo('/view/service/report/errorhot/errorReportDetail.html', 'view/service/report/errorhot/errorReportDetail.html', {
						serviceNo: serviceNo,
						planId: planId,
						noticeId: noticeId,
						errId: errId,
						submitStatus: submitStatus,
						reportGuid:reportGuid
					});
				}else {
					app.jumpTo('/view/service/report/errorhot/errorReportEdit.html', 'view/service/report/errorhot/errorReportEdit.html', {
						serviceNo: serviceNo,
						planId: planId,
						noticeId: noticeId,
						errId: errId,
						submitStatus: submitStatus
					});
				}
			}
			
			function jumpToHotAccountEdit(serviceNo, planId, noticeId, hotAccountId, submitStatus,reportNo) {

				if(submitStatus === 1){
					app.jumpTo('/view/service/report/errorhot/hotReportDetail.html', 'view/service/report/errorhot/hotReportDetail.html', {
						serviceNo: serviceNo,
						planId: planId,
						noticeId: noticeId,
						hotId: hotAccountId,
						submitStatus: submitStatus,
						divBu: divBu,
						reportNo:reportNo
					});

				}else {

					app.jumpTo('/view/service/report/errorhot/hotReportEdit.html', 'view/service/report/errorhot/hotReportEdit.html', {
						serviceNo: serviceNo,
						planId: planId,
						noticeId: noticeId,
						hotId: hotAccountId,
						submitStatus: submitStatus,
						divBu: divBu,
					});
				}
			}
			
			var needDelErrorReportId;
			function fixedDel1() {
				mui("#popover1").popover('toggle', document.getElementById("div1"));
				app.showWaiting("删除中...")
				ajaxGet(BASE_URL + 'cc/error/report/delErrorReport', {
					id: needDelErrorReportId,
					enginnerId: app.getUser().enginnerId
				}, function(data){
					app.closeWaiting()
					if (data.code === 200) {
						app.toast("删除成功")
						errList()
					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg){
					app.closeWaiting()
					app.toast(errorMsg)
				});
			}
			
			function closePopover1() {
				mui("#popover1").popover('toggle', document.getElementById("div1"));
			}
			
			function delErrorReport(reportId) {
				needDelErrorReportId = reportId
				mui("#popover1").popover('toggle', document.getElementById("div1"));
			}
			
			var needDelHotAccountReportId;
			function fixedDel2() {
				mui("#popover2").popover('toggle', document.getElementById("div2"));
				app.showWaiting("删除中...")
				ajaxGet(BASE_URL + 'cc/error/report/delErrorReport', {
					id: needDelHotAccountReportId,
					enginnerId: app.getUser().enginnerId
				}, function(data){
					app.closeWaiting()
					if (data.code === 200) {
						app.toast("删除成功")
						hotList()
					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg){
					app.closeWaiting()
					app.toast(errorMsg)
				});
			}
			
			function closePopover2() {
				mui("#popover2").popover('toggle', document.getElementById("div2"));
			}
			
			function delHotAccountReport(reportId) {
				needDelHotAccountReportId = reportId
				mui("#popover2").popover('toggle', document.getElementById("div2"));
			}
			
			function noData() {
				html = '<div class="nodata">—— 暂无数据 ——</div>';
				h("#itemBox").html(html);
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
